package br.quest.models;

import java.util.Date;
import org.w3c.dom.Element;
import com.google.android.maps.GeoPoint;
import android.content.ContentValues;
import android.database.Cursor;
import android.location.Location;
import br.quest.AbstractModel;

public class Waypoint extends AbstractModel {

    private Location point;
    private GeoPoint geoPoint;
    private Date timestamp;
    private int route_id;

    private final String KEY_LAT = "latitude";
    private final String KEY_LNG = "longitude";
    private final String KEY_TIME = "timestamp";
    private final String KEY_ROUTE_ID = "route_id";

    public Waypoint(Location point, Date timestamp) {
        setCoord(point);
        this.timestamp = timestamp;
        route_id = 0;
    }

    public ContentValues getContentValues() {
        ContentValues values = new ContentValues();
        values.put(KEY_LAT, point.getLatitude());
        values.put(KEY_LNG, point.getLongitude());
        values.put(KEY_TIME, getTime());
        values.put(KEY_ROUTE_ID, route_id);
        return values;
    }

    public static AbstractModel readFromCursor(Cursor c) {
        throw new UnsupportedOperationException("Method not yet implemented");
    }

    public static AbstractModel readFromXML(Element e) {
        throw new UnsupportedOperationException("Method not yet implemented");
    }

    public String[] getColumns() {
        return new String[] { KEY_LAT, KEY_LNG, KEY_TIME, KEY_ROUTE_ID };
    }

    public String getSqlCreate() {
        throw new UnsupportedOperationException("Method not yet implemented");
    }

    public Location getCoord() {
        return point;
    }
    
    public GeoPoint getGeoPoint() {
        return geoPoint;
    }

    public void setCoord(Location coord) {
        point = coord;
        geoPoint = new GeoPoint((int) (point.getLatitude() * 1E6), (int) (point.getLongitude() * 1E6));
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public long getTime() {
        return timestamp.getTime();
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }
}
